<%@page import="java.util.*"%>
<%@page import="java.text.*"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %> 
<%
    String path = request.getContextPath(); 
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+path+ "/"; 
     
%>
<!DOCTYPE HTML>
<html>
<head>
<base href="<%=basePath%>">
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
	<title>新增或修改账户信息</title>
	<link rel="stylesheet" href="bootstrap-3.3.7-dist/css/bootstrap.min.css" />
	<link rel="stylesheet" href="css/bootstrap-datetimepicker.css" />
    <link rel="stylesheet" href="bootstrap-table/dist/bootstrap-table.css">
    <link rel="stylesheet" type="text/css" href="css/xcConfirm.css" />
	<link rel="stylesheet" href="http://fonts.googleapis.com/css?family=Open+Sans:400,300" />
	<link rel="stylesheet" href="http://cache.amap.com/lbs/static/main1119.css"/>
	<link rel="stylesheet" href="bootstrap-fileinput-master/css/fileinput.min.css">
    
    <link rel="shortcut icon" href="favicon.ico" type="image/x-icon" />
    <link rel="stylesheet" href="css/font.css">
    <link rel="stylesheet" href="css/xadmin.css">
    
    <style type="text/css">
        #panel {
            position: absolute;
            background-color: white;
            max-height: 90%;
            overflow-y: auto;
            top: 10px;
            right: 10px;
            width: 280px;
        }
        .td1{
			float:left;
			width:50px;
			display: block; 
			valign:middle;
		}
		.td2{
			float:left;
			width:200px;
			display: block; 
			valign:middle;
		}
		.td3{
			float:left;
			width:660px;
			display: block; 
			valign:middle;
		}
    </style>
</head>
<body>
	<div class="x-body">
            <div   class="form-horizontal" role="form">
              <input id="id" name="id" type="hidden" value="${user.gId}">
			  <div class="form-group">
			  <label for="firstname" class="col-sm-2 control-label">*姓名:</label>
			    <div class="col-sm-3">
			      <input type="text" class="form-control" id="name" name="name" required="required" placeholder="请输入姓名" value="${user.gName}"/>
			    </div>
			  </div>
			  
			  <div class="form-group">
			  <label for="firstname" class="col-sm-2 control-label">*账号:</label>
			    <div class="col-sm-3">
				    <c:if test="${user.gAccount!=null}">
				      <input type="text" class="form-control" id="account" readonly="readonly" name="account" required="required" placeholder="请输入账号" value="${user.gAccount}"/>
			        </c:if>
			        <c:if test="${user.gAccount==null}">
				      <input type="text" class="form-control" id="account" name="account" required="required" placeholder="请输入账号"/>
			        </c:if>
			    </div>
			  </div>
			  
			  <div class="form-group">
			  <label for="firstname" class="col-sm-2 control-label">*密码:</label>
			    <div class="col-sm-3">
			      <c:if test="${user.gPassword!=null}">
			          <input type="password" class="form-control" readonly="readonly" id="password" name="password" required="required" value="${user.gPassword}"/>
			      </c:if>
			      <c:if test="${user.gPassword==null}">
			          <input type="password" class="form-control" readonly="readonly" id="password" name="password" required="required" value="123456"/>
			      </c:if>
			    </div>
			  </div>
			  
			  <div class="form-group">
			      <label for="firstname" class="col-sm-2 control-label">授予角色:</label>
			      <div class="col-sm-3">
			         <select id="role" class="form-control">
             		
              	     </select>
			       </div>
			  </div>
			  
			  <div class="form-group">
			    <label for="firstname" class="col-sm-2 control-label">启用状态:</label>
			    <div class="col-sm-3">
			      <select id="status" class="form-control">
             		<option value="1" <c:if test="${user.gStatus==1}">selected="selected"</c:if>>启用</option>
             		<option value="2" <c:if test="${user.gStatus==2}">selected="selected"</c:if>>禁用</option>
              	  </select>
			    </div>
			  </div>
            
     	<div class="form-group" style="padding-left: 30%">
        
        <button type="submit"   onclick="save()"  class="btn btn-info" >保存</button>
        <button type="reset"    onclick="cancel()"  class="btn btn-info" >取消 </button>
   
     </div>
          </div>
	</div>
        <script src="lib/layui/layui.js" charset="utf-8">
        </script>
        <script src="js/x-layui.js" charset="utf-8">
        </script>
        <!-- 加载需要的js -->
		<script src="js/jquery-3.2.1.min.js"></script>
		<script src="bootstrap-3.3.7-dist/js/bootstrap.min.js"></script>
		<script src="js/jquery-bootstrap-pagination.js"></script>
		<script src="js/qunit-1.11.0.js"></script>
		<script src="js/bootstrap-datetimepicker.js"></script>
		<script src="js/bootstrap-datetimepicker.zh-CN.js"></script>
	    <script src="js/xcConfirm.js" type="text/javascript" charset="utf-8"></script>
	    <script src="bootstrap-fileinput-master/js/fileinput.min.js"></script>
		<script src="bootstrap-fileinput-master/js/locales/zh.js"></script>
        <script>
            layui.use(['form','layer','upload'], function(){
                $ = layui.jquery;
              var form = layui.form()
              ,layer = layui.layer;
              });
            
          //时间插件
    		$('.form_date').datetimepicker({
    	        language:  'zh-CN',
    	        weekStart: 1,
    	        todayBtn:  1,
    			autoclose: 1,
    			todayHighlight: 1,
    			startView: 2,
    			minView: 2,
    			forceParse: 0
    	    });
    		
          
    		//角色列表
	   	   	$(function(){
	   	   		 $.ajax({
	   	               type: "get",
	   	               url: "common/getRoleList",
	   	               dataType:"json",
	   	               success: function(data){    
	   	              	
	   	             	  if(data.code==200){	           	              
	   	             		var htm='';
	   	             		    htm +='<option value=" ">请选择</option>';
	   	            		for (var i = 0; i < data.data.length; i++) {
	   	   	   				var bean = data.data;
	   	   	   				htm +='<option value="'+bean[i].gId+'" code="'+bean[i].gRoleName+'">'+bean[i].gRoleName+'</option>';
	   	     				}
	   	            		$("#role").html(htm);
	   	            	    //角色回显
	   	            		var s1 = '${user.gRole}';
	   	          			var optionss = $("#role").children();
	   	          			for (var i = 0; i < optionss.length; i++) {
	   	          				if (optionss[i].value == s1) {
	   	          					optionss[i].selected = true;
	   	          				}
	   	          			}
	   	          	 	  }
	   	        	      
	   	               }
	   	           });  
	   	   	});
          
            function save(){
	    	     var gId = $("#id").val();
	   		   	 var gName = $("#name").val();
	   		   	 if(gName == null||gName=="") {
	   		   		layer.msg('姓名不能为空!',{icon:2,time:2000});
					  return ;
	   		   	 }
	   		     var gAccount = $("#account").val();
	   			 if(gAccount == null||gAccount=="") {
	   				layer.msg('账号不能为空!',{icon:2,time:2000});
					  return ;
	   		   	 } 
	   			 var gPassword = $("#password").val();
	   		     var gRole = $("#role").find("option:selected").val();
			 	 if(gRole == null||gRole==" ") {
					layer.msg('授予角色不能为空!',{icon:2,time:2000});
					  return ;
			   	 }
			 	 var gStatus = $("#status").find("option:selected").val();
			 	 if(gStatus == null||gStatus==" ") {
					layer.msg('状态不能为空!',{icon:2,time:2000});
					  return ;
			   	 }
	   			 var  data = {"gId":gId,"gName":gName,"gAccount":gAccount,"gPassword":gPassword,"gRole":gRole,
	   		          	 "gStatus":gStatus}
	   	         
	   	         $.ajax({
	   	             type: "post",
	   	             url: "sysUser/insertOrUpdate",
	   	             data: JSON.stringify(data),
	   	             contentType:"application/json;charset=UTF-8", 
	   	             dataType:"json",
	   	             success: function(data){    
		   	           	  if(data.code==200){
		   	           	      layer.alert(data.msg, {icon: 6},function () {
			   	           		  parent.location.reload();
			                      // 获得frame索引
			                      var index = parent.layer.getFrameIndex(window.name);
			                      //关闭当前frame
			                      parent.layer.close(index);
			                      parent.location.reload();
			                  });    
				          }else{
				    	      var txt=data.msg;
				      	    	   layer.alert(txt); 
				      	  }
                    }
   	         });  
   	         
   			}
   	   
   	   function cancel(){
   		   	
   		// 获得frame索引
           var index = parent.layer.getFrameIndex(window.name);
           //关闭当前frame
           parent.layer.close(index);
   	         
   			}
        </script>
</body>
</html>